﻿using System.Windows.Controls;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using Might.Infrastructure.Services;
using Might.Infrastructure.View;
using Might.Services.Logger;

namespace Might.Services {
    /// <summary>
    /// Implementation of Logger.
    /// </summary>
    public class ServicesModule : IModule {
        private readonly IRegionManager regionManager;
        private readonly IUnityContainer container;
        private IEventAggregator eventAggregator;

        /// <summary>
        /// Initializes a new instance of the <see cref="ServicesModule"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="regionManager">The region manager.</param>
        /// <param name="eventAggregator">The event aggregator.</param>
        public ServicesModule(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator) {
            this.regionManager = regionManager;
            this.container = container;
            this.eventAggregator = eventAggregator;
        }

        /// <summary>
        /// Initializes this instance and register global services for other modules.
        /// </summary>
        public void Initialize() {
            MightLogger logger = new MightLogger(container);
            //IRegion loggerRegion = regionManager.Regions["LoggerRegion"];
            //loggerRegion.Add(logger.View);
            ((Border)MyRegionManager.Get("LoggerRegion")).Child = logger.View;
            container.RegisterInstance(typeof (IMightLogger), logger);

            //ModalDialog modalDlg = new ModalDialog( container );
            //container.RegisterInstance( typeof( IModalDialog ) , modalDlg );

            container.RegisterType<IModalDialog, ModalDialog>();
        }
    }
}
